#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int coinChange(vector<int>& coins, int aim) {
        int n = coins.size();
        vector<vector<int>>dp(n + 1, vector<int>(aim + 1));
        for (int j = 1; j <= aim; j++) dp[0][j] = INT_MAX;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= aim; j++)
            {
                dp[i][j] = dp[i - 1][j];
                if (j >= coins[i - 1] && dp[i][j - coins[i - 1]] != INT_MAX) dp[i][j] = min(dp[i][j], dp[i][j - coins[i - 1]] + 1);
            }
        }
        return dp[n][aim] == INT_MAX ? -1 : dp[n][aim];
    }
};
/*class Solution {
public:
    int coinChange(vector<int>& coins, int aim) {
    int n=coins.size();
    vector<int>dp(aim+1);
    for(int j=1;j<=aim;j++) dp[j]=INT_MAX;
    for(int i=1;i<=n;i++)
    {
        for(int j=coins[i-1];j<=aim;j++)
        {
         if(dp[j-coins[i-1]]!=INT_MAX)
         dp[j]=min(dp[j],dp[j-coins[i-1]]+1);
        }
    }
    return dp[aim]>=INT_MAX ? -1 : dp[aim];
    }
};*/